package com.itheima.d4_stringbuilder;

//需求：对比String和StringBuilder操作字符串的效率（看效果）
public class Demo1 {
    public static void main(String[] args) {
        //test1();
        //test2();
    }

    public static void test1() {
        String str = "";
        long start = System.currentTimeMillis();
        for (int i = 0; i < 1000000; i++) {
            str += i;
        }
        long end = System.currentTimeMillis();
        System.out.println("String：" + (end - start) + "毫秒");
    }

    public static void test2() {
        StringBuilder sb = new StringBuilder();
        long start = System.currentTimeMillis();
        for (int i = 0; i < 1000000; i++) {
            sb.append(i);
        }
        long end = System.currentTimeMillis();
        System.out.println("StringBuilder：" + (end - start) + "毫秒");
    }
}
